class Solution {
public:
    vector<int> minOperations(string boxes) {
        int left = boxes[0] - '0', right = 0;
        vector<int> res(boxes.size(), 0);
        for (int i = 1; i < boxes.size(); ++i) {
            if (boxes[i] == '1') {
                ++right;
                res[0] += i;
            }
        }
        for (int i = 1; i < boxes.size(); ++i) {
            res[i] = res[i - 1] + left - right;
            if (boxes[i] == '1') {
                ++left;
                --right;
            }
        }
        return res;
    }
};